<template>
  <div class="user-search default-radius">
    <el-form :model="userSearchForm" ref="formRef" label-width="120px" size="large">
      <el-row :gutter="20">
        <el-col :span="8">
          <el-form-item label="部门名称" prop="name">
            <el-input v-model="userSearchForm.name" placeholder="请输入查询的部门名称" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="部门领导" prop="leader">
            <el-input v-model="userSearchForm.leader" placeholder="请输入部门领导" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="创建时间" prop="createAt">
            <el-date-picker
              type="daterange"
              range-separator="-"
              start-placeholder="开始时间"
              end-placeholder="结束时间"
              v-model="userSearchForm.createAt"
            />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <!-- 1.2.搜索按钮  -->
    <div class="btns">
      <el-button size="large" icon="Refresh" @click="handleResetClick">重置</el-button>
      <el-button size="large" icon="Search" type="primary" @click="handleQueryClick">
        查询
      </el-button>
    </div>
  </div>
</template>

<script setup lang="ts">
import { reactive, ref } from 'vue';
import type { FormInstance } from 'element-plus';

const formRef = ref<FormInstance>();
const userSearchForm = reactive({
  name: '',
  leader: '',
  createAt: ''
});
const emits = defineEmits(['queryClick', 'resetClick']);

function handleResetClick() {
  formRef.value?.resetFields();
  emits('resetClick');
}

function handleQueryClick() {
  emits('queryClick', userSearchForm);
}
</script>

<style scoped lang="scss">
.user-search {
  padding: 20px;
  background-color: #ffffff;
  .el-form {
    padding-top: 20px;
    padding-right: 10px;
  }

  .el-form-item {
    padding: 20px 40px;
    margin-bottom: 0;
  }
  .btns {
    text-align: right;
    padding: 0 50px 10px 0;
  }
}
</style>
